winsafe\mf\com_interfaces/
imfattributes.rs

1#![allow(non_camel_case_types, non_snake_case)]
2
3use crate::co;
4use crate::decl::*;
5use crate::guard::*;
6use crate::kernel::privs::*;
7use crate::mf::vts::*;
8use crate::ole::privs::*;
9use crate::prelude::*;
10
11com_interface! { IMFAttributes: "2cd2d921-c447-44a7-a13c-4adabfc247e3";
12	/// [`IMFAttributes`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nn-mfobjects-imfattributes)
13	/// COM interface.
14	///
15	/// Automatically calls
16	/// [`Release`](https://learn.microsoft.com/en-us/windows/win32/api/unknwn/nf-unknwn-iunknown-release)
17	/// when the object goes out of scope.
18}
19
20impl mf_IMFAttributes for IMFAttributes {}
21
22/// This trait is enabled with the `mf` feature, and provides methods for
23/// [`IMFAttributes`](crate::IMFAttributes).
24///
25/// Prefer importing this trait through the prelude:
26///
27/// ```no_run
28/// use winsafe::prelude::*;
29/// ```
30pub trait mf_IMFAttributes: ole_IUnknown {
31	/// [`IMFAttributes::Compare`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-compare)
32	/// method.
33	#[must_use]
34	fn Compare(
35		&self,
36		theirs: &impl mf_IMFAttributes,
37		match_type: co::MF_ATTRIBUTES_MATCH,
38	) -> HrResult<bool> {
39		let mut res = 0;
40		ok_to_hrresult(unsafe {
41			(vt::<IMFAttributesVT>(self).Compare)(
42				self.ptr(),
43				theirs.ptr(),
44				match_type.raw(),
45				&mut res,
46			)
47		})
48		.map(|_| res != 0)
49	}
50
51	/// [`IMFAttributes::CompareItem`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-compareitem)
52	/// method.
53	#[must_use]
54	fn CompareItem(&self, guid_key: &GUID, value: &PropVariant) -> HrResult<bool> {
55		let mut res = 0;
56		ok_to_hrresult(unsafe {
57			(vt::<IMFAttributesVT>(self).CompareItem)(
58				self.ptr(),
59				pcvoid(guid_key),
60				pcvoid(&value.to_raw()?),
61				&mut res,
62			)
63		})
64		.map(|_| res != 0)
65	}
66
67	/// [`IMFAttributes::CopyAllItems`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-copyallitems)
68	/// method.
69	fn CopyAllItems(&self, dest: &impl mf_IMFAttributes) -> HrResult<()> {
70		ok_to_hrresult(unsafe {
71			(vt::<IMFAttributesVT>(self).CopyAllItems)(self.ptr(), dest.ptr())
72		})
73	}
74
75	fn_com_noparm! { DeleteAllItems: IMFAttributesVT;
76		/// [`IMFAttributes::DeleteAllItems`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-deleteallitems)
77		/// method.
78	}
79
80	/// [`IMFAttributes::DeleteItem`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-deleteitem)
81	/// method.
82	fn DeleteItem(&self, guid_key: &GUID) -> HrResult<()> {
83		ok_to_hrresult(unsafe {
84			(vt::<IMFAttributesVT>(self).DeleteItem)(self.ptr(), pcvoid(guid_key))
85		})
86	}
87
88	/// [`IMFAttributes::GetAllocatedBlob`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getallocatedblob)
89	/// method.
90	///
91	/// Note that this method allocates the buffer twice, whereas
92	/// [`IMFAttributes::GetBlob`](crate::prelude::mf_IMFAttributes::GetBlob)
93	/// allocates only once, thus being more efficient.
94	#[must_use]
95	fn GetAllocatedBlob(&self, guid_key: &GUID) -> HrResult<Vec<u8>> {
96		let mut pbuf = std::ptr::null_mut::<u8>();
97		let mut sz = u32::default();
98
99		ok_to_hrresult(unsafe {
100			(vt::<IMFAttributesVT>(self).GetAllocatedBlob)(
101				self.ptr(),
102				pcvoid(guid_key),
103				&mut pbuf,
104				&mut sz,
105			)
106		})
107		.map(|_| {
108			let raw = unsafe { CoTaskMemFreeGuard::new(pbuf as *mut _, sz as _) };
109			raw.as_slice().to_vec()
110		})
111	}
112
113	/// [`IMFAttributes::GetAllocatedString`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getallocatedstring)
114	/// method.
115	///
116	/// Note that this method allocates the buffer twice, whereas
117	/// [`IMFAttributes::GetString`](crate::prelude::mf_IMFAttributes::GetString)
118	/// allocates only once, thus being more efficient.
119	#[must_use]
120	fn GetAllocatedString(&self, guid_key: &GUID) -> HrResult<String> {
121		let mut pbuf = std::ptr::null_mut::<u16>();
122		let mut nchars = u32::default();
123
124		ok_to_hrresult(unsafe {
125			(vt::<IMFAttributesVT>(self).GetAllocatedString)(
126				self.ptr(),
127				pcvoid(guid_key),
128				&mut pbuf,
129				&mut nchars,
130			)
131		})
132		.map(|_| {
133			let str = unsafe { WString::from_wchars_nullt(pbuf) };
134			let _ = unsafe { CoTaskMemFreeGuard::new(pbuf as _, 0) };
135			str.to_string()
136		})
137	}
138
139	/// [`IMFAttributes::GetBlob`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getblob)
140	/// method.
141	///
142	/// Calls
143	/// [`IMFAttributes::GetBlobSize`](crate::prelude::mf_IMFAttributes::GetBlobSize)
144	/// to alloc the buffer.
145	#[must_use]
146	fn GetBlob(&self, guid_key: &GUID) -> HrResult<Vec<u8>> {
147		let sz = self.GetBlobSize(guid_key)?;
148		let mut buf = vec![0u8; sz as _];
149
150		ok_to_hrresult(unsafe {
151			(vt::<IMFAttributesVT>(self).GetBlob)(
152				self.ptr(),
153				pcvoid(guid_key),
154				buf.as_mut_ptr(),
155				sz,
156				std::ptr::null_mut(),
157			)
158		})
159		.map(|_| buf)
160	}
161
162	/// [`IMFAttributes::GetBlobSize`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getblobsize)
163	/// method.
164	#[must_use]
165	fn GetBlobSize(&self, guid_key: &GUID) -> HrResult<u32> {
166		let mut sz = u32::default();
167		ok_to_hrresult(unsafe {
168			(vt::<IMFAttributesVT>(self).GetBlobSize)(self.ptr(), pcvoid(guid_key), &mut sz)
169		})
170		.map(|_| sz)
171	}
172
173	/// [`IMFAttributes::GetCount`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getcount)
174	/// method.
175	#[must_use]
176	fn GetCount(&self) -> HrResult<u32> {
177		let mut count = u32::default();
178		ok_to_hrresult(unsafe { (vt::<IMFAttributesVT>(self).GetCount)(self.ptr(), &mut count) })
179			.map(|_| count)
180	}
181
182	/// [`IMFAttributes::GetDouble`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getdouble)
183	/// method.
184	#[must_use]
185	fn GetDouble(&self, guid_key: &GUID) -> HrResult<f64> {
186		let mut value = f64::default();
187		ok_to_hrresult(unsafe {
188			(vt::<IMFAttributesVT>(self).GetDouble)(self.ptr(), pcvoid(guid_key), &mut value)
189		})
190		.map(|_| value)
191	}
192
193	/// [`IMFAttributes::GetGUID`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getguid)
194	/// method.
195	#[must_use]
196	fn GetGUID(&self, guid_key: &GUID) -> HrResult<GUID> {
197		let mut value = GUID::default();
198		ok_to_hrresult(unsafe {
199			(vt::<IMFAttributesVT>(self).GetGUID)(self.ptr(), pcvoid(guid_key), pvoid(&mut value))
200		})
201		.map(|_| value)
202	}
203
204	/// [`IMFAttributes::GetItem`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getitem)
205	/// method.
206	#[must_use]
207	fn GetItem(&self, guid_key: &GUID) -> HrResult<PropVariant> {
208		let mut value = PROPVARIANT::default();
209		ok_to_hrresult(unsafe {
210			(vt::<IMFAttributesVT>(self).GetItem)(self.ptr(), pcvoid(guid_key), pvoid(&mut value))
211		})?;
212		PropVariant::from_raw(&value)
213	}
214
215	/// [`IMFAttributes::GetItemByIndex`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getitembyindex)
216	/// method.
217	#[must_use]
218	fn GetItemByIndex(&self, index: u32) -> HrResult<(GUID, PropVariant)> {
219		let mut guid = GUID::default();
220		let mut value = PROPVARIANT::default();
221
222		ok_to_hrresult(unsafe {
223			(vt::<IMFAttributesVT>(self).GetItemByIndex)(
224				self.ptr(),
225				index,
226				pvoid(&mut guid),
227				pvoid(&mut value),
228			)
229		})?;
230		Ok((guid, PropVariant::from_raw(&value)?))
231	}
232
233	/// [`IMFAttributes::GetItemType`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getitemtype)
234	/// method.
235	#[must_use]
236	fn GetItemType(&self, guid_key: &GUID) -> HrResult<co::MF_ATTRIBUTE> {
237		let mut ty = co::MF_ATTRIBUTE::default();
238		ok_to_hrresult(unsafe {
239			(vt::<IMFAttributesVT>(self).GetItemType)(self.ptr(), pcvoid(guid_key), ty.as_mut())
240		})
241		.map(|_| ty)
242	}
243
244	/// [`IMFAttributes::GetString`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getstring)
245	/// method.
246	///
247	/// Calls
248	/// [`IMFAttributes::GetStringLength`](crate::prelude::mf_IMFAttributes::GetStringLength)
249	/// to alloc the buffer.
250	#[must_use]
251	fn GetString(&self, guid_key: &GUID) -> HrResult<String> {
252		let len = self.GetStringLength(guid_key)? + 1;
253		let mut buf = WString::new_alloc_buf(len as _);
254
255		ok_to_hrresult(unsafe {
256			(vt::<IMFAttributesVT>(self).GetString)(
257				self.ptr(),
258				pcvoid(guid_key),
259				buf.as_mut_ptr(),
260				len,
261				std::ptr::null_mut(),
262			)
263		})
264		.map(|_| buf.to_string())
265	}
266
267	/// [`IMFAttributes::GetStringLength`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getstringlength)
268	/// method.
269	#[must_use]
270	fn GetStringLength(&self, guid_key: &GUID) -> HrResult<u32> {
271		let mut len = u32::default();
272		ok_to_hrresult(unsafe {
273			(vt::<IMFAttributesVT>(self).GetStringLength)(self.ptr(), pcvoid(guid_key), &mut len)
274		})
275		.map(|_| len)
276	}
277
278	/// [`IMFAttributes::GetUINT32`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getuint32)
279	/// method.
280	fn GetUINT32(&self, guid_key: &GUID) -> HrResult<u32> {
281		let mut value = u32::default();
282		ok_to_hrresult(unsafe {
283			(vt::<IMFAttributesVT>(self).GetUINT32)(self.ptr(), pcvoid(guid_key), &mut value)
284		})
285		.map(|_| value)
286	}
287
288	/// [`IMFAttributes::GetUINT64`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getuint64)
289	/// method.
290	fn GetUINT64(&self, guid_key: &GUID) -> HrResult<u64> {
291		let mut value = u64::default();
292		ok_to_hrresult(unsafe {
293			(vt::<IMFAttributesVT>(self).GetUINT64)(self.ptr(), pcvoid(guid_key), &mut value)
294		})
295		.map(|_| value)
296	}
297
298	/// [`IMFAttributes::GetUnknown`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getunknown)
299	/// method.
300	#[must_use]
301	fn GetUnknown<T>(&self, guid_key: &GUID) -> HrResult<T>
302	where
303		T: ole_IUnknown,
304	{
305		let mut queried = unsafe { T::null() };
306		ok_to_hrresult(unsafe {
307			(vt::<IMFAttributesVT>(self).GetUnknown)(
308				self.ptr(),
309				pcvoid(guid_key),
310				pcvoid(&T::IID),
311				queried.as_mut(),
312			)
313		})
314		.map(|_| queried)
315	}
316
317	fn_com_noparm! { LockStore: IMFAttributesVT;
318		/// [`IMFAttributes::LockStore`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-lockstore)
319		/// method.
320	}
321
322	/// [`IMFAttributes::SetBlob`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-setblob)
323	/// method.
324	fn SetBlob(&self, guid_key: &GUID, buf: &[u8]) -> HrResult<()> {
325		ok_to_hrresult(unsafe {
326			(vt::<IMFAttributesVT>(self).SetBlob)(
327				self.ptr(),
328				pcvoid(guid_key),
329				vec_ptr(buf),
330				buf.len() as _,
331			)
332		})
333	}
334
335	/// [`IMFAttributes::SetDouble`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-setdouble)
336	/// method.
337	fn SetDouble(&self, guid_key: &GUID, value: f64) -> HrResult<()> {
338		ok_to_hrresult(unsafe {
339			(vt::<IMFAttributesVT>(self).SetDouble)(self.ptr(), pcvoid(guid_key), value)
340		})
341	}
342
343	/// [`IMFAttributes::SetGUID`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-setguid)
344	/// method.
345	fn SetGUID(&self, guid_key: &GUID, value: &GUID) -> HrResult<()> {
346		ok_to_hrresult(unsafe {
347			(vt::<IMFAttributesVT>(self).SetGUID)(self.ptr(), pcvoid(guid_key), pcvoid(value))
348		})
349	}
350
351	/// [`IMFAttributes::SetItem`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-setitem)
352	/// method.
353	fn SetItem(&self, guid_key: &GUID, value: &PropVariant) -> HrResult<()> {
354		ok_to_hrresult(unsafe {
355			(vt::<IMFAttributesVT>(self).SetItem)(
356				self.ptr(),
357				pcvoid(guid_key),
358				pcvoid(&value.to_raw()?),
359			)
360		})
361	}
362
363	/// [`IMFAttributes::SetString`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-setstring)
364	/// method.
365	fn SetString(&self, guid_key: &GUID, value: &str) -> HrResult<()> {
366		ok_to_hrresult(unsafe {
367			(vt::<IMFAttributesVT>(self).SetString)(
368				self.ptr(),
369				pcvoid(guid_key),
370				WString::from_str(value).as_ptr(),
371			)
372		})
373	}
374
375	/// [`IMFAttributes::SetUINT32`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-setuint32)
376	/// method.
377	fn SetUINT32(&self, guid_key: &GUID, value: u32) -> HrResult<()> {
378		ok_to_hrresult(unsafe {
379			(vt::<IMFAttributesVT>(self).SetUINT32)(self.ptr(), pcvoid(guid_key), value)
380		})
381	}
382
383	/// [`IMFAttributes::SetUINT64`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-setuint64)
384	/// method.
385	fn SetUINT64(&self, guid_key: &GUID, value: u64) -> HrResult<()> {
386		ok_to_hrresult(unsafe {
387			(vt::<IMFAttributesVT>(self).SetUINT64)(self.ptr(), pcvoid(guid_key), value)
388		})
389	}
390
391	/// [`IMFAttributes::SetUnknown`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-setunknown)
392	/// method.
393	fn SetUnknown(&self, guid_key: &GUID, value: &impl ole_IUnknown) -> HrResult<()> {
394		ok_to_hrresult(unsafe {
395			(vt::<IMFAttributesVT>(self).SetUnknown)(self.ptr(), pcvoid(guid_key), value.ptr())
396		})
397	}
398
399	fn_com_noparm! { UnlockStore: IMFAttributesVT;
400		/// [`IMFAttributes::UnlockStore`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-unlockstore)
401		/// method.
402	}
403}